/**
 * 详情对话框
 */
var GcgWsjdInfoDlg = {
    tableId: "menuTable",
    data: {
        gcgWsjdId: "",
        gcgProjectId: "",
        yaoma: "",
        mingcheng: "",
        dizhiSheng: "",
        dizhiShengView: "",
        dizhiShi: "",
        dizhiShiView: "",
        dizhiXianqu: "",
        dizhiXianquView: "",
        dizhiXiangxi: "",
        pinpai: "",
        guishu: "",
        mdTel: "",
        lxrName: "",
        lxrTel: "",
        jsTel: "",
        pinlei: "",
        mdYysj: "",
        isTcw: "",
        tcwPrice: "",
        renjunPrice: "",
        farenXingming: "",
        yhkName: "",
        yhkHao: "",
        isFapiao: "",
        isYouhui: "",
        farenSfzPic1: "",
        farenSfzPic2: "",
        farenSfzPic3: "",
        dzSfzPic1: "",
        dzSfzPic2: "",
        dzSfzPic3: "",
        yingyeZhizhao: "",
        shipinXkz: "",
        zfbShouquan: "",
        mentouPics: "",
        neijingPics: "",
        shStatus: "",
        createTime: "",
        createUser: "",
        updateTime: "",
        updateUser: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects','tree','ztree','treetable','table'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var tree = layui.tree;
    var $ZTree = layui.ztree;
    var treetable = layui.treetable;
    var table = layui.table;

    /**
     * 初始化表格的列
     */
    GcgWsjdInfoDlg.initColumn = function () {
        return [[
            //{type: 'numbers'},
            {type: 'checkbox'},
            {field: 'gcgWsjdShenpixiangId', hide: true, sort: true, title: 'id'},
            {field: 'name', align: "left", sort: false, title: '美团团购', minWidth: 240},
            {field: 'miaoshu', align: "left", sort: false, title: '驳回原因', minWidth: 240,edit: 'text'},
            // {field: 'code', align: "center", sort: true, title: '菜单编号', minWidth: 120},
            // {field: 'pcode', align: "center", sort: true, title: '菜单父编号'},
            // {field: 'url', align: "center", sort: true, title: '请求地址'},
            // {field: 'sort', align: "center", sort: true, title: '排序'},
            // {field: 'levels', align: "center", sort: true, title: '层级'},
            // {field: 'isMenuName', align: "center", sort: true, title: '是否是菜单'},
            // {field: 'statusName', align: "center", sort: true, title: '状态'},
            // {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 200}
        ]];
    };

    /**
     * 点击菜单树时
     */
    GcgWsjdInfoDlg.onClickMenu = function (e, treeId, treeNode) {
        GcgWsjdInfoDlg.condition.menuId = treeNode.id;
        GcgWsjdInfoDlg.search();
    };

    /**
     * 点击查询按钮
     */
    GcgWsjdInfoDlg.search = function () {
        var queryData = {};
        queryData['menuName'] = $("#menuName").val();
        queryData['level'] = $("#level").val();
        queryData['gcgWsjdId'] = $("#gcgWsjdId").val();
        GcgWsjdInfoDlg.initTable(GcgWsjdInfoDlg.tableId, queryData);
    };

    //监听单元格编辑
    // table.on('edit(menuTable)', function (obj) {
    //     var value = obj.value //得到修改后的值
    //         , data = obj.data //得到所在行所有键值
    //         , field = obj.field; //得到字段
    //     //编辑
    //     var miaoshu = data.miaoshu;
    //     //alert(miaoshu);
    //     var gcgWsjdId=$("#gcgWsjdId").val();
    //     //alert(gcgWsjdId);
    //     data.gcgWsjdId=gcgWsjdId;
    //     $.ajax({
    //         type: "PUT",
    //         url: "/gcgWsjd/editItem",
    //         datatype: "json",
    //         data: data,
    //         success: function (data) {
    //             // if(data==2){
    //             //     Feng.error("已报销，不能修改");
    //             //     table.reload(Notice.tableId);
    //             // }
    //             //Feng.success("修改成功！");
    //              table.reload(GcgWsjdInfoDlg.tableId);
    //         }, error: function () {
    //             Feng.error("修改失败！");
    //         }, complete: function (XHR, TS) {
    //             //layer.close(layerIndex);
    //             //50秒自动刷新一次
    //             //setTimeout(showTime,50000);
    //         }
    //
    //     });
    //     //layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
    // });









    /**
     * 初始化表格
     */
    GcgWsjdInfoDlg.initTable = function (menuId, data) {
        var gcgWsjdId=$("#gcgWsjdId").val();
        return treetable.render({
            elem: '#' + menuId,
            url: Feng.ctxPath + '/gcgWsjd/listTree?gcgWsjdId='+gcgWsjdId,
            where: data,
            page: false,
            height: "full-98",
            cellMinWidth: 100,
            cols: GcgWsjdInfoDlg.initColumn(),
            treeColIndex: 2,
            treeSpid: "0",
            treeIdName: 'gcgWsjdShenpixiangId',
            treePidName: 'pid',
            done:function (res,data) {
                $('th[data-field=' + 0 +'] input[type="checkbox"]').prop('disabled', true);
                res.data.forEach(function (item, index) {
                    if (item.name === "基本信息") {
                        $(".layui-table").find('tr[data-index="'+ index +'"]').find('td').data('edit', false);
                        $('tr[data-index=' + index + '] input[type="checkbox"]').prop('disabled', true);
                    }
                    if (item.name === "前厅/客服电话") {
                        $(".layui-table").find('tr[data-index="'+ index +'"]').find('td').data('edit', false);
                        $('tr[data-index=' + index + '] input[type="checkbox"]').prop('disabled', true);
                    }
                    if (item.name === "金融信息") {
                        $(".layui-table").find('tr[data-index="'+ index +'"]').find('td').data('edit', false);
                        $('tr[data-index=' + index + '] input[type="checkbox"]').prop('disabled', true);
                    }
                })

                // $(".layui-table").find('tr[data-index="'+ 0 +'"]').find('td').data('edit', false);
                // $(".layui-table").find('tr[data-index="'+ 5 +'"]').find('td').data('edit', false);
                // $(".layui-table").find('tr[data-index="'+ 8 +'"]').find('td').data('edit', false);
            }
            //     //tabTitle();//调用方法
            // }
        });
    };

    // 渲染表格
    var tableResult = GcgWsjdInfoDlg.initTable(GcgWsjdInfoDlg.tableId);
    $('#expandAll').click(function () {
        treetable.expandAll('#' + GcgWsjdInfoDlg.tableId);
    });
    $('#foldAll').click(function () {
        treetable.foldAll('#' + GcgWsjdInfoDlg.tableId);
    });



    //初始化左侧部门树
    var ztree = new $ZTree("menuTree", "/gcgWsjd/selectMenuTreeList");
    ztree.bindOnClick(GcgWsjdInfoDlg.onClickMenu);
   // ztree.init();

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        GcgWsjdInfoDlg.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        GcgWsjdInfoDlg.openAddMenu();
    });

    // 工具条点击事件
    table.on('tool(' + GcgWsjdInfoDlg.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            GcgWsjdInfoDlg.onEditMenu(data);
        } else if (layEvent === 'delete') {
            GcgWsjdInfoDlg.onDeleteMenu(data);
        } else if (layEvent === 'roleAssign') {
            GcgWsjdInfoDlg.roleAssign(data);
        } else if (layEvent === 'reset') {
            GcgWsjdInfoDlg.resetPassword(data);
        }
    });

    /**
     * 驳回
     */
    form.on('submit(btnSubmit)', function (data) {
        var checkRows = table.checkStatus(GcgWsjdInfoDlg.tableId);
        var data = checkRows.data;

        if (!data.length){
            Feng.error("请选择要批量完成的数据");
            return
        }
        var tempList = ['basic','jinrong','md_tel']
        for (let i=0; i<data.length;i++){
            if(data[i].miaoshu.length == 0 && tempList.indexOf(data[i].code) < 0) {
                Feng.error("请填写驳回原因");
                return
            }
        }

        var ajax = new $ax(Feng.ctxPath + "/gcgWsjd/rejectMt", function (data) {
            Feng.success("驳回成功!");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("驳回失败!" + data.responseJSON.message + "!");
        });
        ajax.set("id", $("#gcgWsjdId").val());
        ajax.set("data", JSON.stringify(data));
        ajax.start();

    });








































































































// 驳回按钮点击事件
//     $('#btnSearch').click(function () {
//         GcgWsjdInfoDlg.Rebut();
//     });












    //表单提交事件
    // form.on('submit(btnSubmit)', function (data) {
    //     var ajax = new $ax(Feng.ctxPath + "/gcgWsjd/editItem", function (data) {
    //         Feng.success("驳回成功！");
    //         //传给上个页面，刷新table用
    //         admin.putTempData('formOk', true);
    //         //关掉对话框
    //         admin.closeThisDialog();
    //     }, function (data) {
    //         Feng.error("驳回失败！" + data.responseJSON.message)
    //     });
    //     // var gcgWsjdId=$("#gcgWsjdId").val();
    //     // data.field.gcgWsjdId=gcgWsjdId;
    //     ajax.set(data.field);
    //     ajax.start();
    //
    //     return false;
    // });

});